package com.example.javamaday.leetcode;

import java.util.Comparator;
import java.util.PriorityQueue;

public class LeetCodeTest0215 {

    public static void main(String[] args) {

    }

    public int findKthLargest(int[] nums, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>(k, new Comparator<Integer>() {
            @Override
            public int compare(Integer t1, Integer t2) {
                return t2.compareTo(t1);
            }
        });
        for (int i = 0; i < nums.length; i++) {
            queue.add(nums[i]);
        }
        System.out.println("Size = " + queue.size());
        int index = 0;
        int result = 0;
        while (queue.size() > 0) {
            if (index == k) {
                result = queue.poll();
                System.out.println("Set Size = " + queue.size());
                break;
            } else {
                queue.poll();
                index++;
                System.out.println("Set Size = " + queue.size());
            }
        }
        return result;
    }
}
